﻿using System;
using System.Collections.ObjectModel;
using System.Linq;

namespace MDrive.ViewModels
{
    public class MDriveViewModel : ViewModelBase
    {
        public ObservableCollection<MDriveParameterViewModel> MDriveParameterViewModels { get; private set; }

        private string _program;
        public String Program
        {
            get { return _program; }
            set { SetProperty(ref _program, value); }
        }

        public MDriveViewModel()
        {
            MDriveParameterViewModels = new ObservableCollection<MDriveParameterViewModel>();

            // Commands: BP, BR, CF, CL, CP, CR, DC, E, EX, FD, H, HI, IC, IV, L, LB, MA, MR, PG, PR, PS, RS, RT, S, SL, TA, VA
            MDriveParameterViewModels.Add(new MDriveParameterViewModel("A", "Acceleration"));
            MDriveParameterViewModels.Add(new MDriveParameterViewModel("C1", "Pulse"));
            MDriveParameterViewModels.Add(new MDriveParameterViewModel("C2", "Encoder"));
            MDriveParameterViewModels.Add(new MDriveParameterViewModel("D", "Deceleration"));
            MDriveParameterViewModels.Add(new MDriveParameterViewModel("DB", "Dead Band"));
            MDriveParameterViewModels.Add(new MDriveParameterViewModel("EE", "Encoder Enable"));
            MDriveParameterViewModels.Add(new MDriveParameterViewModel("ER", "Error"));
            MDriveParameterViewModels.Add(new MDriveParameterViewModel("HC", "Hold Current"));
            MDriveParameterViewModels.Add(new MDriveParameterViewModel("I1", "Input"));
            MDriveParameterViewModels.Add(new MDriveParameterViewModel("I2", "Input"));
            MDriveParameterViewModels.Add(new MDriveParameterViewModel("I3", "Input"));
            MDriveParameterViewModels.Add(new MDriveParameterViewModel("I4", "Input"));
            MDriveParameterViewModels.Add(new MDriveParameterViewModel("MA", "Move Absolute", true));
            MDriveParameterViewModels.Add(new MDriveParameterViewModel("MR", "Move Relative", true));
            MDriveParameterViewModels.Add(new MDriveParameterViewModel("MS", "Microstep"));
            MDriveParameterViewModels.Add(new MDriveParameterViewModel("MV", "Moving"));
            //MDriveParameterViewModels.Add(new MDriveParameterViewModel("O1", "Output"));
            //MDriveParameterViewModels.Add(new MDriveParameterViewModel("O2", "Output"));
            //MDriveParameterViewModels.Add(new MDriveParameterViewModel("O3", "Output"));
            //MDriveParameterViewModels.Add(new MDriveParameterViewModel("O4", "Output"));
            MDriveParameterViewModels.Add(new MDriveParameterViewModel("P", "Position"));
            MDriveParameterViewModels.Add(new MDriveParameterViewModel("PM", "Position Maintenance"));
            MDriveParameterViewModels.Add(new MDriveParameterViewModel("R1", "Register"));
            MDriveParameterViewModels.Add(new MDriveParameterViewModel("R2", "Register"));
            MDriveParameterViewModels.Add(new MDriveParameterViewModel("R3", "Register"));
            MDriveParameterViewModels.Add(new MDriveParameterViewModel("R4", "Register"));
            MDriveParameterViewModels.Add(new MDriveParameterViewModel("RC", "Run Current"));
            MDriveParameterViewModels.Add(new MDriveParameterViewModel("SF", "Stall Factor"));
            MDriveParameterViewModels.Add(new MDriveParameterViewModel("SL", "Slew", true));
            MDriveParameterViewModels.Add(new MDriveParameterViewModel("SM", "Stall Mode"));
            MDriveParameterViewModels.Add(new MDriveParameterViewModel("ST", "Stall"));
            MDriveParameterViewModels.Add(new MDriveParameterViewModel("V", "Velocity"));
            MDriveParameterViewModels.Add(new MDriveParameterViewModel("VI", "Initial Velocity"));
            MDriveParameterViewModels.Add(new MDriveParameterViewModel("VM", "Maximum Velocity"));
            MDriveParameterViewModels.Add(new MDriveParameterViewModel("Z1", "User"));
            MDriveParameterViewModels.Add(new MDriveParameterViewModel("Z2", "User"));
            MDriveParameterViewModels.Add(new MDriveParameterViewModel("Z3", "User"));
            MDriveParameterViewModels.Add(new MDriveParameterViewModel("Z4", "User"));
        }

        public MDriveParameterViewModel FindMDriveParameterViewModel(String symbol)
        {
            return MDriveParameterViewModels.FirstOrDefault(mDriveParameterViewModel => mDriveParameterViewModel.Symbol == symbol);
        }

        private Boolean _readRequest;
        public Boolean ReadRequest
        {
            get { return _readRequest; }
            set { SetProperty(ref _readRequest, value); }
        }

        private Boolean _sendRequest;
        public Boolean SendRequest
        {
            get { return _sendRequest; }
            set { SetProperty(ref _sendRequest, value); }
        }

        private Boolean _runRequest;
        public Boolean RunRequest
        {
            get { return _runRequest; }
            set { SetProperty(ref _runRequest, value); }
        }

        private Boolean _endRequest;
        public Boolean EndRequest
        {
            get { return _endRequest; }
            set { SetProperty(ref _endRequest, value); }
        }
    }
}
